$('document').ready(function(){
    $('img','#tbListaPermissaoUsuario tbody').click(function(){
        $(this).attr('id', 'trabalhandoComORegistro');
        var src = $(this).attr('src');
        //alert('opa');
        $.post('permissao.php',{idUsuario: $(this).attr('name'),acao: src, idAcao:jsGet('id')},
        function(data){
            var end = "img/negar.png";
            var img = trim(data);
           alt = end!=img?'Negar a permissao deste usuario':'Permitir esta acao ao usuario';
            $('#trabalhandoComORegistro').attr({'src' :img, 'alt' :alt, 'title' :alt, 'id' :''} );
        });
    });
});

$('document').ready(function(){
    $('img','#tbListaPermissaoGrupo tbody').click(function(){
        $(this).attr('id', 'trabalhandoComORegistro');
        var src = $(this).attr('src');
        $.post('permissaogrupo.php',{idGrupo: $(this).attr('name'),acao: src, idAcao:jsGet('id')},
        function(data){
            var end = "img/negar.png";
            var img = trim(data);
            alt = end!=img?'Negar a permissao deste grupo':'Permitir esta acao ao grupo';
            $('#trabalhandoComORegistro').attr({'src' :img, 'alt' :alt, 'title' :alt, 'id' :''} );
        });
    });

});
function ltrim(str) {
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}


function urlDecode(string, overwrite){
    if(!string || !string.length){
        return {};
    }
    var obj = {};
    var pairs = string.split('&');
    var pair, name, value;
    var lsRegExp = /\+/g;
    for(var i = 0, len = pairs.length; i < len; i++){
        pair = pairs[i].split('=');
        name = unescape(pair[0]);
        value = unescape(pair[1]).replace(lsRegExp, " ");
        //value = decodeURIComponent(pair[1]).replace(lsRegExp, " ");
        if(overwrite !== true){
            if(typeof obj[name] == "undefined"){
                obj[name] = value;
            }else if(typeof obj[name] == "string"){
                obj[name] = [obj[name]];
                obj[name].push(value);
            }else{
                obj[name].push(value);
            }
        }else{
            obj[name] = value;
        }
    }
    return obj;
}


function jsGet(param)
{
	var wl = window.location.href;
	var params = urlDecode(wl.substring(wl.indexOf("?")+1));
	return(params[param]);
}
